const { string } = require('joi');
// 引入mongoose模块
const mongoose = require('mongoose');

// 创建集合规则
const articleSchema = new mongoose.Schema({
    // 文章标题
    title: {
        type: String,
        minlength: [2, '标题长度至少是2个字符长度'],
        maxlength: [30, '标题长度最多是30个字符长度'],
        required: true
    },
    // 文章作者id
    writer: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User',
        required: true
    },
    // 文章封面
    cover: {
        type: String,
        default: null
    },
    // 文章内容
    content: {
        type: String,
        required: true
    },
    // 文章发布时间
    publishDate: {
        type: Date,
        default: Date.now
    }
});

// 引用集合规则
const Article = mongoose.model('Article', articleSchema);

// 导出规则
module.exports = Article;